package com.entrogy.service.impl;

import com.entrogy.bean.DepartmentEntity;
import com.entrogy.bean.PositionEntity;
import com.entrogy.dao.DepartmentMapper;

import com.entrogy.service.DepartmentService;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.binding.BindingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public int insertDepartment(DepartmentEntity departmentEntity) {
        return departmentMapper.insertDepartment(departmentEntity);
    }
    @Override
    public int updateDepartment(DepartmentEntity departmentEntity) {
        return departmentMapper.updateDepartment(departmentEntity);
    }
    @Override
    public int deleteDepartment(int department_id) {
        return departmentMapper.deleteDepartment(department_id);
    }

    @Override
    public int getSchoolId(int sid) {
        return departmentMapper.getSchoolId(sid);
    }
    /**
     *
     * @param map  获取部门的查询列表
     * @return
     */
    @Override
    public List<Map<String,Object>> selectDepartmentByT(Map<String,Object> map){
        List<Map<String,Object>> list=departmentMapper.selectDepartmentByT(map);
        for (int i=0;i<list.size();i++){
            list.get(i).put("create_time",list.get(i).get("create_time").toString().substring(0,10));
            list.get(i).put("update_time",list.get(i).get("update_time").toString().substring(0,10));
        }

        return list;
    };

    /**
     *
     * @param map  获取部门的查询列表  根据条件查询条数
     * @return
     */
    @Override
    public int  countDepartment(Map<String,Object> map){
        return departmentMapper.countDepartment(map);
    };

    /**
     *  获取职位列表
     * @return
     */
    @Override
    public List<PositionEntity>  getPositionList(Map<String,Object> map){
        return departmentMapper.getPositionList(map);
    };

    /**
     *   分页查询总数
     * @param map
     * @return
     */
    @Override
    public int  getTotalPositionList(Map<String,Object> map){
        return departmentMapper.getTotalPositionList(map);
    };

    /**
     *  修改职位名称
     * @return
     */
    @Override
    public int  updatePositionById(PositionEntity positionEntity){
        return departmentMapper.updatePositionById(positionEntity);
    };

    /**
     *  根据Id  查询对象
     * @param id
     * @return
     */
    @Override
    public PositionEntity  getPositionById(int id){
        return  departmentMapper.getPositionById(id);
    };

    /**
     *   新增基础数据
     * @param schoolCode
     * @return
     */
    @Override
    public int  insertPositions( int schoolCode){
        return  departmentMapper.insertPositions(schoolCode);
    };

    /**
     *  删除基础数据
     * @param schoolCode
     * @return
     */
    @Override
    public int deleteBySchoolCode( int schoolCode){
        return  departmentMapper.deleteBySchoolCode(schoolCode);
    };

    /**
     *  selectPositionId
     * @param map
     * @return
     */
    @Override
    public int selectPositionId(Map<String,Object> map){
        try {
            return  departmentMapper.selectPositionId(map);
                    }
        catch (BindingException e){
            return  0;
        }


    };
}
